// npm install @alicloud/dm20151123@1.0.5
import Dm20151123, * as $Dm20151123 from '@alicloud/dm20151123';
// 依赖的模块可通过下载工程中的模块依赖文件或右上角的获取 SDK 依赖信息查看
import OpenApi, * as $OpenApi from '@alicloud/openapi-client';
import Util, * as $Util from '@alicloud/tea-util';
import * as util from "util";
import {inspect} from "util";

const accessKeyId = process.env.ACCESSKEYID;
const accessKeySecret = process.env.ACCESSKEYSECRET;
export default class Client {

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    static createClient(accessKeyId: string, accessKeySecret: string): Dm20151123 {
        let config = new $OpenApi.Config({
            // 必填，您的 AccessKey ID
            accessKeyId: accessKeyId,
            // 必填，您的 AccessKey Secret
            accessKeySecret: accessKeySecret,
        });
        // 访问的域名
        config.endpoint = `dm.aliyuncs.com`;
        return new Dm20151123(config);
    }

    static async main(args: string[]): Promise<void> {
        // 工程代码泄露可能会导致AccessKey泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考，建议使用更安全的 STS 方式，更多鉴权访问方式请参见：https://help.aliyun.com/document_detail/378664.html
        // @ts-ignore
        let client = Client.createClient(accessKeyId, accessKeySecret);
        let singleSendMailRequest = new $Dm20151123.SingleSendMailRequest({
            accountName: "cto@mail.mongyu.cn",
            addressType: 1,
            toAddress: "uibemba_admin@163.com",
            subject: "阿里邮件推送",
            fromAlias: "网站名称",
            replyAddress: "1026911109@qq.com",
            replyAddressAlias: "网站管理员",
            replyToAddress: true,
            textBody: "32432432",
        });
        let runtime = new $Util.RuntimeOptions({ });
        try {
            // 复制代码运行请自行打印 API 的返回值
            const res = await client.singleSendMailWithOptions(singleSendMailRequest, runtime);
            console.log(inspect(res, false,null,true));

        } catch (error) {

            // 如有需要，请打印 error
            // @ts-ignore
            Util.assertAsString(error.message);
        }
    }

}

Client.main(process.argv.slice(2));